package cn.com.yusys.yusp.message.service.message.channel.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.yusys.yusp.admin.service.AdminSmNoticeService;
import cn.com.yusys.yusp.commons.util.DateUtil;
import cn.com.yusys.yusp.commons.util.StringUtil;
import cn.com.yusys.yusp.message.service.message.channel.SystemSendInterface;
import cn.com.yusys.yusp.notice.dto.AdminSmNoticeDTO;

@Service("DefaultSystemSendImpl")
public class DefaultSystemSendImpl implements SystemSendInterface{

    private final static Logger logger = LoggerFactory.getLogger(DefaultSystemSendImpl.class);
    
    @Autowired
    AdminSmNoticeService noticeService;

	@Override
	public int sendMessage(String userNo,String title, String content) {
		try {
		    AdminSmNoticeDTO dto = new AdminSmNoticeDTO();
		    dto.setNoticeId(StringUtil.getUUID());
		    if (StringUtil.isEmpty(title)) {
		        dto.setNoticeTitle("无");
		    } else {
		        dto.setNoticeTitle(title);
		    }
		    dto.setNoticeContent(content);
		    dto.setPubTime(DateUtil.formatDateTimeByDef());
		    dto.setPubUserId(userNo);
		    noticeService.noticeInsert(dto);
			return 0;
		} catch (Exception e) {
			logger.error("Failed to send system message ", e);
			return 1;
		}
	}


}
